#ifndef REQUEST_HPP
#define REQUEST_HPP
#include <string>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "Listener.hpp"

class Listener;

using namespace boost::asio;
class Request {
	io_service &io;
	ip::tcp::socket sock;
	deadline_timer keepalive_timer;
	strand st;
	Listener *listener;

	boost::asio::streambuf req_data;
	boost::asio::streambuf resp_data;

	// An http protocol request data
	std::string uri;
	std::string host;
	std::string docroot;
	struct stat filestat;
	void writeanswer();
	void setup_timer();

	void wr_sendfile(std::string path, const boost::system::error_code& error);
public:
	ip::tcp::socket &socket() { return sock; }
	Request(io_service &ior);
	~Request();
	void start(const boost::system::error_code& error);
	void finish(const boost::system::error_code& error);
	void answer_code(int code);
	void handle_request_headers(const boost::system::error_code& error, size_t bytes_transferred);
};

#endif

